package com.fattyCorps.battle.service.battle.behavior.state;

import com.fattyCorps.battle.service.battle.Battle;
import com.fattyCorps.battle.service.battle.behavior.Behavior;
import com.fattyCorps.battle.service.battle.behavior.BhvBlackboard;
import com.fattyCorps.battle.service.battle.behavior.BhvProcessor;
import com.fattyCorps.battle.service.battle.behavior.condition.BhvTrgCnd;
import com.fattyCorps.battle.service.battle.data.BattleHero;
import com.fattyCorps.common.obj.config.SkillBehaviorMould;
import com.fattyCorps.common.util.fsm.FsmState;

// 触发行为条件筛选
public class SBhvFiler extends FsmState {
    BhvTrgCnd trgCond;

    @Override
    public void onEnter() {
        SkillBehaviorMould cfg = (SkillBehaviorMould)getBlackboard(BhvBlackboard.BHV_CFG);
        Battle battle = (Battle)getBlackboard(BhvBlackboard.BATTLE);
        BhvProcessor.Event e = (BhvProcessor.Event)getBlackboard(BhvBlackboard.EVENT);
        BattleHero owner = (BattleHero)getBlackboard(BhvBlackboard.BHV_OWNER);
        Behavior bhv = (Behavior)getBlackboard(BhvBlackboard.BHV);

        trgCond = new BhvTrgCnd();
        trgCond.init(cfg.getTriggerConditionId(), battle);

        if (!battle.getBhvProcessor().isCounterBhv(bhv, e.getCounterBhvTypes()) && trgCond.canTrigger(e, owner, bhv)) {
            getMch().setState(SSelectTgt.class);
        }
    }
}
